package io.github.hadyang.leetcode.offer;

import org.junit.Test;

/**
 * https://www.nowcoder.com/questionTerminal/4060ac7e3e404ad1a894ef3e17650423
 *
 * @author haoyang.shi
 */
public class StringSpace {

  @Test
  public void test() {
    System.out.println(replaceSpace(new StringBuffer("We Are Happy.")));
  }

  public String replaceSpace(StringBuffer str) {
    char[] chars = str.toString().toCharArray();
    StringBuilder res = new StringBuilder();

    for (char c : chars) {
      if (c == ' ') res.append("%20");
      else res.append(c);
    }

    return res.toString();
  }
}
